#{extends 'main.html' /} 
#{set title:'View Sprint BackLog' /}
<script>
	jQuery(function($){
		$(".SBtiptip").tipTip({
			fadeIn:30,
			fadeOut:30
		});
		
		$('.editAssignee').editable({
                onSubmit: editAssignee
            });
			$('.edit').editable({
                onSubmit: effort
            });
        });
	var rowVisible = true;
        function toggleDisplay(tbl, name){
            var tblRows = tbl.rows;
            for (i = 0; i < tblRows.length; i++) {
                if (tblRows[i].className != "StroyRow" && tblRows[i].className == name) {
                    tblRows[i].style.display = (rowVisible) ? "none" : "";
                }
            }
            rowVisible = !rowVisible;
        }
</script>
<link rel="stylesheet" href="/public/stylesheets/tableStyle.css" />
<h2>${comp.name} Sprint Backlog</h2><hr/>
<div  style="overflow:scroll; height:500px; width=900px">
<table id="SPRNTBcklog" border=4 align="center" cellspacing=0>
	<thead>
    <tr>
        <th>
            Sprint Name: 
        </th>
        <th>
        	<a href="@{Events.showSprint(sp.getEntityId())}">${sp.name}</a>
        </th>
        <th align="center">
            Initial
            <br>
            </br>
            Estimated
            <br>
            </br>
            points 
            <br>
            </th>
			<th colspan="${sd}">
				Effort Points Remaining
			</th>
            
        </tr>
        <br>
        <tr>
        	<th></th>
            <th align="center">
                WHO? 
            </th>
            <th align="center">
                Day 
                <br>
                </br>
                0 
            </th>
            #{list items:forSprintduration, as:'Day'}
            <th>
                Day
                <br>
                </br>
                ${Day}
            </th>
            #{/list}
        </tr>
        <tr>
            <th style="border:none">
            </th>
            <th style="border:none">
            </th>
            <th>
            </th>
                #{list items:forSprintduration, as:'Day'}
                <th>
                </th>
                #{/list}
            </tr>
			</thead>
			<tbody>
           		 <tr>
           		 	<!--Stories-->
     			#{if allPs!=null} 
                #{list items:allPs, as:'stories'}
				#{if compID==stories.component.id}
                <tr class="${stories}">
                    <th class="th2" colspan="2">
                    	<h3 class="Tablecomponent">${stories.story}</h3>
                    	 <td align="left" style="border:none">
                		<img id="ex_col" onclick="toggleDisplay(document.getElementById('SPRNTBcklog'),'${stories.story}')" src="/public/images/plusmin.gif"/>
				</td>
                    </th>
					
                    #{list items:stories.tasks,as:'Tasklist'}
					#{if Tasklist.initialEffortEstimation != 0.0}
                    <tr class="${stories.story}">
                        <td align="right">
                        	#{if Tasklist.type.type=="Impediment"}
								<img class="SBtiptip" src="/public/images/obstacles.jpg" title="This is an impediment task" align="center"/>
							#{/if}
                            ${Tasklist.description}
							
                        </td>
						#{if controllers.Events.sprintInProgress(sp.id)}
						 #{if controllers.Security.checkPermission(' edit the assignee of a task ',pro)== true}
						<td id="${Tasklist.id}" class="editAssignee SBtiptip" title="You Can edit the assignee of the task"> #{if controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).lastName} #{/if}</td>
						#{/if}
						#{else}
						<td id="${Tasklist.id}"> #{if controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).lastName} #{/if}</td>
						#{/else}
						#{/if}
						#{else}
						<td> #{if controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).lastName} #{/if}</td>
						#{/else}
                        <td align="center">
                            ${Tasklist.initialEffortEstimation}
                        </td>
						<!--This is the days empty cell beside each task-->

						%{i=0;}%
						#{list items:controllers.SprintBacklog.getEffortsTillNow2(sp.id,Tasklist.id), as:'Effrt'}
						%{
						  i++;
						  }%
						    #{if controllers.Users.isSystemAdmin()==true}
						  <td id="${Tasklist.id}" text="${Effrt.id}" class="edit SBtiptip" title="You Can Enter Remaining Effort">#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/if}
						 #{elseif controllers.Events.sprintInProgress(sp.id)}
						  #{if controllers.SprintBacklog.assignedmem(Tasklist.id)}
						<td id="${Tasklist.id}" text="${Effrt.id}" class="edit SBtiptip" title="Enter Ur Remaining Effort" >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/if}
						#{else}
						<td >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/else}
						#{/elseif}
						#{else}
						<td >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/else}
						#{/list}
                    </tr>
					#{/if}
					#{/list}
					
                </tr>
					#{/if}
                	#{/list}
					#{/if}
					<!--End of stories-->
						</tbody>
        </table>
	</div>
  <br></br>
  <script>
  	function editAssignee(content){	
	if(content.current == "" || content.current == null)
		window.location.reload(true);
		else{
        		$.post('@{Tasks.editTaskAssignee()}',
        	{taskId:content.id,
        	newValue:content.current,
			proId:'${projectID}'},function(){
						window.location.reload(true);});
        		}

        }
		function effort(content){
			
			if (isNaN(content.current) || content.current == "" || content.current == null||content.current>99 || content.current<0);
				else{
				if (content.previous == "" || content.previous == null) {
					$.post('@{SprintBacklog.addDayEditEffort()}', {
						sprintId: '${sp.id}',
						taskId: content.id,
						effort: content.current,
						dayNum: content.text
					}, function(){
						window.location.reload(true);
					});
				}
				else {
					$.post('@{SprintBacklog.editEffort()}', {
						sprintId: '${sp.id}',
						taskId: content.id,
						effort: content.current,
						dayNum: content.text,
						oldEffort: content.previous
					}, function(){
						window.location.reload(true);
					});
				}
			}

       	}
		
  
  </script>